package com.bsbm.common.bean;

import org.richfaces.component.UITree;
//import org.richfaces.event.NodeExpandedEvent;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;

import javax.faces.component.UIComponent;

public class MyBackingBean{

    /**
     * The tree expand expand listener method.
     */
   /* public void processExpansion(NodeExpandedEvent nodeExpandedEvent){
// get the source or the component who fired this event.
        Object source = nodeExpandedEvent.getSource();
        if (source instanceof HtmlTreeNode) {
            // It should be a html tree node, if yes get
            // the ui tree which contains this node.
            UITree tree = ((HtmlTreeNode) source).getUITree();
// avoid null pointer exceptions even though not needed. but safety first ;-)
            if (tree == null) {
                return;
            }
            // get the row key i.e. id of the given node.
            Object rowKey = tree.getRowKey();
            // get the model node of this node.
            TreeNode selectedTreeModelNode =  tree.getModelTreeNode(rowKey);
            if(null != selectedTreeModelNode){
                // add the children nodes.
                addChildrenNodes(selectedTreeModelNode);
            }
        }
    } */
    /**
     * Method for adding children nodes to a given tree model node.
     */
  /*  public void addChildrenNodes(TreeNode node){
        //process your node somehow. For this example I add only one node.
        TreeNodeImpl newNode = new TreeNodeImpl();
        newNode.setData("My New Node");
        newNode.setParent(node);
        node.addChild("rowKey", newNode);
    }  */
    /**
     * The select node listener method.
     */
  /*  public void selectNode(NodeSelectedEvent event){
        // get the component that fired this event.
        UIComponent component = event.getComponent();
        if (component instanceof HtmlTree) {
            // if a rich faces html tree (it is sometimes also a ui tree)
            //get the row key of selected node.
            Object rowKey = ((HtmlTree) component).getRowKey();
            //pull the model tree node out of ther.
            TreeNode selectedTreeModelNode = ((HtmlTree) component).getModelTreeNode(rowKey);
            if(null != selectedTreeModelNode){
                // add the children to the model.
                addChildrenNodes(selectedTreeModelNode);
            }
        }
    }
    private org.richfaces.component.state.TreeState treeState;

    public void setTreeState(org.richfaces.component.state.TreeState treeState) {
        this.treeState = treeState;
    }

    public org.richfaces.component.state.TreeState getTreeState() {
        return treeState;
    }

    public void selectNode(NodeSelectedEvent event) throws Exception {

        // ... same as in the previous section
        if(null != selectedTreeModelNode){
            //....  as in previous section
            // queue the node to be expanded.
            getTreeState().expandNode((UITree) tree,
                    (TreeRowKey) rowKey);
        }
    }
    } */
}
